<!DOCTYPE html><html class="theme-next gemini use-motion" lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta name="theme-color" content="#222"><script src="/MyBlog/lib/pace/pace.min.js?v=1.0.2"></script><link href="/MyBlog/lib/pace/pace-theme-loading-bar.min.css?v=1.0.2" rel="stylesheet"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/MyBlog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"><link href="/MyBlog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/MyBlog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css"><link rel="apple-touch-icon" sizes="180x180" href="/MyBlog/images/apple-touch-icon-next.png?v=5.1.4"><link rel="icon" type="image/png" sizes="32x32" href="/MyBlog/images/bitbug_favicon.ico?v=5.1.4"><link rel="icon" type="image/png" sizes="16x16" href="/MyBlog/images/bitbug_favicon16.ico?v=5.1.4"><link rel="mask-icon" href="/MyBlog/images/logo.svg?v=5.1.4" color="#222"><meta name="keywords" content="Vue,"><meta name="description" content="&amp;emsp;&amp;emsp;Moment.js是一个轻量级的JavaScript时间库，它方便了日常开发中对时间的操作，提高了开发效率。日常开发中，通常会对时间进行下面这几个操作：比如获取时间，设置时间，格式化时间，比较时间等等。下面就是我对moment.js使用过程中的整理，方便以后查阅。引入moment.js安装npm install moment –save或者 yarn add moment引"><meta property="og:type" content="article"><meta property="og:title" content="moment.js使用方法总结"><meta property="og:url" content="https://gitee.com/yang_yu_xiang/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/index.html"><meta property="og:site_name" content="Yang&#39;s Blog"><meta property="og:description" content="&amp;emsp;&amp;emsp;Moment.js是一个轻量级的JavaScript时间库，它方便了日常开发中对时间的操作，提高了开发效率。日常开发中，通常会对时间进行下面这几个操作：比如获取时间，设置时间，格式化时间，比较时间等等。下面就是我对moment.js使用过程中的整理，方便以后查阅。引入moment.js安装npm install moment –save或者 yarn add moment引"><meta property="og:image" content="https://gitee.com/yang_yu_xiang/BlogImages/raw/master/img/%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%B6%E9%97%B4.png"><meta property="article:published_time" content="2020-11-03T14:59:44.000Z"><meta property="article:modified_time" content="2020-11-04T01:48:24.270Z"><meta property="article:author" content="杨雨翔"><meta property="article:tag" content="Vue"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://gitee.com/yang_yu_xiang/BlogImages/raw/master/img/%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%B6%E9%97%B4.png"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/MyBlog/",scheme:"Gemini",version:"5.1.4",sidebar:{position:"left",display:"post",offset:12,b2t:!1,scrollpercent:!0,onmobile:!0},fancybox:!0,tabs:!0,motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}},duoshuo:{userId:"0",author:"博主"},algolia:{applicationID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}}}</script><link rel="canonical" href="https://gitee.com/yang_yu_xiang/MyBlog/2020/11/03/moment-js使用方法总结/"><title>moment.js使用方法总结 | Yang's Blog</title><meta name="generator" content="Hexo 4.2.1"></head><body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans"><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><a href="https://gitee.com/yang_yu_xiang" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513;color:#fff;position:absolute;top:0;border:0;right:0" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style><header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><div class="custom-logo-site-title"><a href="/MyBlog/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">Yang's Blog</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">永远年轻 永远热泪盈眶</p></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/MyBlog/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i><br>首页</a></li><li class="menu-item menu-item-tags"><a href="/MyBlog/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i><br>标签</a></li><li class="menu-item menu-item-categories"><a href="/MyBlog/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i><br>分类</a></li><li class="menu-item menu-item-archives"><a href="/MyBlog/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i><br>归档</a></li><li class="menu-item menu-item-search"><a href="javascript:;" class="popup-trigger"><i class="menu-item-icon fa fa-search fa-fw"></i><br>搜索</a></li></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-block"><link itemprop="mainEntityOfPage" href="https://gitee.com/yang_yu_xiang/MyBlog/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="杨雨翔"><meta itemprop="description" content=""><meta itemprop="image" content="https://gitee.com/yang_yu_xiang/BlogImages/raw/master/img/psb.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Yang's Blog"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">moment.js使用方法总结</h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-11-03T22:59:44+08:00">2020-11-03 </time><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于&#58;</span> <time title="更新于" itemprop="dateModified" datetime="2020-11-04T09:48:24+08:00">2020-11-04 </time></span><span class="post-comments-count"><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><a href="/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/" itemprop="commentCount"></span> </a></span><span class="post-meta-divider">|</span> <span class="page-pv">本文总阅读数 <i class="fa fa-file-o"></i> <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次</span><div class="post-wordcount"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">字数统计&#58;</span> <span title="字数统计">1.6k </span><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span title="阅读时长">7</span></div></div></header><div class="post-body" itemprop="articleBody"><p>&emsp;&emsp;<code>Moment.js</code>是一个轻量级的JavaScript时间库，它方便了日常开发中对时间的操作，提高了开发效率。日常开发中，通常会对时间进行下面这几个操作：比如获取时间，设置时间，格式化时间，比较时间等等。下面就是我对moment.js使用过程中的整理，方便以后查阅。</p><h1 id="引入moment-js"><a href="#引入moment-js" class="headerlink" title="引入moment.js"></a>引入moment.js</h1><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><blockquote><p>npm install moment –save或者 yarn add moment</p></blockquote><h2 id="引入"><a href="#引入" class="headerlink" title="引入"></a>引入</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// require 方式</span></span><br><span class="line"><span class="keyword">var</span> moment = <span class="built_in">require</span>(<span class="string">'moment'</span>);</span><br><span class="line"><span class="comment">// import 方式</span></span><br><span class="line"><span class="keyword">import</span> moment <span class="keyword">from</span> <span class="string">'moment'</span>;</span><br></pre></td></tr></table></figure><p>浏览器方式引入</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"moment.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure><h1 id="设定moment区域为中国"><a href="#设定moment区域为中国" class="headerlink" title="设定moment区域为中国"></a>设定moment区域为中国</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// require 方式</span></span><br><span class="line"><span class="built_in">require</span>(<span class="string">'moment/locale/zh-cn'</span>)</span><br><span class="line">moment.locale(<span class="string">'zh-cn'</span>); </span><br><span class="line"></span><br><span class="line"><span class="comment">// import 方式</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'moment/locale/zh-cn'</span></span><br><span class="line">moment.locale(<span class="string">'zh-cn'</span>);</span><br></pre></td></tr></table></figure><h1 id="方法速查"><a href="#方法速查" class="headerlink" title="方法速查"></a>方法速查</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">moment() <span class="comment">//获取时间</span></span><br><span class="line"></span><br><span class="line">moment().startOf(<span class="string">'?'</span>)<span class="comment">//获取本周、本月的第一天0时0分0秒</span></span><br><span class="line"></span><br><span class="line">moment().endOf(<span class="string">'?'</span>)<span class="comment">//获取本周、本月的最后一天23时59分59秒</span></span><br><span class="line"></span><br><span class="line">moment().dayInMonth()<span class="comment">//获取当月总天数</span></span><br><span class="line"></span><br><span class="line">moment().unix()<span class="comment">//返回时间戳（number）</span></span><br><span class="line"></span><br><span class="line">moment().get(<span class="string">'?'</span>)</span><br><span class="line">moment().?()<span class="comment">//获取某一事件</span></span><br><span class="line"></span><br><span class="line">moment().set(<span class="string">'?'</span>,num)</span><br><span class="line">moment().?(num)<span class="comment">//设置某一时间</span></span><br><span class="line"></span><br><span class="line">moment().add(num,<span class="string">'?'</span>)<span class="comment">//时间+num</span></span><br><span class="line"></span><br><span class="line">moment().subtract(num,<span class="string">'?'</span>)<span class="comment">//时间-num</span></span><br><span class="line"></span><br><span class="line">moment().format(<span class="string">'xxxxxxx'</span>)<span class="comment">//格式化时间</span></span><br><span class="line"></span><br><span class="line">diff()<span class="comment">//比较时间</span></span><br><span class="line"></span><br><span class="line">toDate()<span class="comment">//时间转换成Date对象</span></span><br><span class="line"></span><br><span class="line">fromNow()<span class="comment">//相对现在的时间</span></span><br><span class="line"></span><br><span class="line">calendar()<span class="comment">//日期时间</span></span><br></pre></td></tr></table></figure><a id="more"></a><h1 id="基本使用"><a href="#基本使用" class="headerlink" title="基本使用"></a>基本使用</h1><h2 id="获取时间"><a href="#获取时间" class="headerlink" title="获取时间"></a>获取时间</h2><h3 id="获取当前时间"><a href="#获取当前时间" class="headerlink" title="获取当前时间"></a>获取当前时间</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment()</span><br></pre></td></tr></table></figure><h3 id="获取今天0时0分0秒"><a href="#获取今天0时0分0秒" class="headerlink" title="获取今天0时0分0秒"></a>获取今天0时0分0秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().startOf(<span class="string">'day'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取本周第一天-周日Sunday-0时0分0秒"><a href="#获取本周第一天-周日Sunday-0时0分0秒" class="headerlink" title="获取本周第一天(周日Sunday)0时0分0秒"></a>获取本周第一天(周日Sunday)0时0分0秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().startOf(<span class="string">'week'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取本周周一0时0分0秒"><a href="#获取本周周一0时0分0秒" class="headerlink" title="获取本周周一0时0分0秒"></a>获取本周周一0时0分0秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().startOf(<span class="string">'isoWeek'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取当前月第一天0时0分0秒"><a href="#获取当前月第一天0时0分0秒" class="headerlink" title="获取当前月第一天0时0分0秒"></a>获取当前月第一天0时0分0秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().startOf(<span class="string">'month'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取今天23时59分59秒"><a href="#获取今天23时59分59秒" class="headerlink" title="获取今天23时59分59秒"></a>获取今天23时59分59秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().endOf(<span class="string">'day'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取本周最后一天-周六-23时59分59秒"><a href="#获取本周最后一天-周六-23时59分59秒" class="headerlink" title="获取本周最后一天(周六)23时59分59秒"></a>获取本周最后一天(周六)23时59分59秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().endOf(<span class="string">'week'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取本周周日23时59分59秒"><a href="#获取本周周日23时59分59秒" class="headerlink" title="获取本周周日23时59分59秒"></a>获取本周周日23时59分59秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().endOf(<span class="string">'isoWeek'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取当前月最后一天23时59分59秒"><a href="#获取当前月最后一天23时59分59秒" class="headerlink" title="获取当前月最后一天23时59分59秒"></a>获取当前月最后一天23时59分59秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().endOf(<span class="string">'month'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取当前月的总天数"><a href="#获取当前月的总天数" class="headerlink" title="获取当前月的总天数"></a>获取当前月的总天数</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().daysInMonth()</span><br></pre></td></tr></table></figure><h3 id="获取时间戳-以秒为单位"><a href="#获取时间戳-以秒为单位" class="headerlink" title="获取时间戳(以秒为单位)"></a>获取时间戳(以秒为单位)</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'X'</span>) <span class="comment">// 返回值为字符串类型</span></span><br><span class="line">moment().unix() <span class="comment">// 返回值为数值型</span></span><br></pre></td></tr></table></figure><h3 id="获取时间戳-以毫秒为单位"><a href="#获取时间戳-以毫秒为单位" class="headerlink" title="获取时间戳(以毫秒为单位)"></a>获取时间戳(以毫秒为单位)</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'x'</span>) <span class="comment">// 返回值为字符串类型</span></span><br><span class="line">moment().valueOf() <span class="comment">// 返回值为数值型</span></span><br></pre></td></tr></table></figure><h3 id="获取年份"><a href="#获取年份" class="headerlink" title="获取年份"></a>获取年份</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().year()</span><br><span class="line">moment().get(<span class="string">'year'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取月份"><a href="#获取月份" class="headerlink" title="获取月份"></a>获取月份</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().month()  <span class="comment">// (0~11, 0: January, 11: December)</span></span><br><span class="line">moment().get(<span class="string">'month'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取一个月中的某一天"><a href="#获取一个月中的某一天" class="headerlink" title="获取一个月中的某一天"></a>获取一个月中的某一天</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().date()</span><br><span class="line">moment().get(<span class="string">'date'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取一个星期中的某一天"><a href="#获取一个星期中的某一天" class="headerlink" title="获取一个星期中的某一天"></a>获取一个星期中的某一天</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">moment().day() <span class="comment">// (0~6, 0: Sunday, 6: Saturday)</span></span><br><span class="line">moment().weekday() <span class="comment">// (0~6, 0: Sunday, 6: Saturday)</span></span><br><span class="line">moment().isoWeekday() <span class="comment">// (1~7, 1: Monday, 7: Sunday)</span></span><br><span class="line">moment().get(<span class="string">'day'</span>)</span><br><span class="line">mment().get(<span class="string">'weekday'</span>)</span><br><span class="line">moment().get(<span class="string">'isoWeekday'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取小时"><a href="#获取小时" class="headerlink" title="获取小时"></a>获取小时</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().hours()</span><br><span class="line">moment().get(<span class="string">'hours'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取分钟"><a href="#获取分钟" class="headerlink" title="获取分钟"></a>获取分钟</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().minutes()</span><br><span class="line">moment().get(<span class="string">'minutes'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取秒数"><a href="#获取秒数" class="headerlink" title="获取秒数"></a>获取秒数</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().seconds()</span><br><span class="line">moment().get(<span class="string">'seconds'</span>)</span><br></pre></td></tr></table></figure><h3 id="获取当前的年月日时分秒"><a href="#获取当前的年月日时分秒" class="headerlink" title="获取当前的年月日时分秒"></a>获取当前的年月日时分秒</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().toArray() <span class="comment">// [years, months, date, hours, minutes, seconds, milliseconds]</span></span><br></pre></td></tr></table></figure><h2 id="设置时间"><a href="#设置时间" class="headerlink" title="设置时间"></a>设置时间</h2><h3 id="设置年份"><a href="#设置年份" class="headerlink" title="设置年份"></a>设置年份</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">moment().year(<span class="number">2019</span>)</span><br><span class="line">moment().set(<span class="string">'year'</span>, <span class="number">2019</span>)</span><br><span class="line">moment().set(&#123;<span class="attr">year</span>: <span class="number">2019</span>&#125;)</span><br></pre></td></tr></table></figure><h3 id="设置月份"><a href="#设置月份" class="headerlink" title="设置月份"></a>设置月份</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().month(<span class="number">11</span>)  <span class="comment">// (0~11, 0: January, 11: December)</span></span><br><span class="line">moment().set(<span class="string">'month'</span>, <span class="number">11</span>)</span><br></pre></td></tr></table></figure><h3 id="设置某个月中的某一天"><a href="#设置某个月中的某一天" class="headerlink" title="设置某个月中的某一天"></a>设置某个月中的某一天</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().date(<span class="number">15</span>)</span><br><span class="line">moment().set(<span class="string">'date'</span>, <span class="number">15</span>)</span><br></pre></td></tr></table></figure><h3 id="设置某个星期中的某一天"><a href="#设置某个星期中的某一天" class="headerlink" title="设置某个星期中的某一天"></a>设置某个星期中的某一天</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">moment().weekday(<span class="number">0</span>) <span class="comment">// 设置日期为本周第一天（周日）</span></span><br><span class="line">moment().isoWeekday(<span class="number">1</span>) <span class="comment">// 设置日期为本周周一</span></span><br><span class="line">moment().set(<span class="string">'weekday'</span>, <span class="number">0</span>)</span><br><span class="line">moment().set(<span class="string">'isoWeekday'</span>, <span class="number">1</span>)</span><br></pre></td></tr></table></figure><h3 id="设置小时"><a href="#设置小时" class="headerlink" title="设置小时"></a>设置小时</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().hours(<span class="number">12</span>)</span><br><span class="line">moment().set(<span class="string">'hours'</span>, <span class="number">12</span>)</span><br></pre></td></tr></table></figure><h3 id="设置分钟"><a href="#设置分钟" class="headerlink" title="设置分钟"></a>设置分钟</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().minutes(<span class="number">30</span>)</span><br><span class="line">moment().set(<span class="string">'minutes'</span>,<span class="number">30</span>)</span><br></pre></td></tr></table></figure><h3 id="设置秒数"><a href="#设置秒数" class="headerlink" title="设置秒数"></a>设置秒数</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().seconds(<span class="number">30</span>)</span><br><span class="line">moment().set(<span class="string">'seconds'</span>, <span class="number">30</span>)</span><br></pre></td></tr></table></figure><h3 id="年份-1"><a href="#年份-1" class="headerlink" title="年份+1"></a>年份+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'years'</span>)</span><br><span class="line">moment().add(&#123;<span class="attr">years</span>: <span class="number">1</span>&#125;)</span><br></pre></td></tr></table></figure><h3 id="月份-1"><a href="#月份-1" class="headerlink" title="月份+1"></a>月份+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'months'</span>)</span><br></pre></td></tr></table></figure><h3 id="日期-1"><a href="#日期-1" class="headerlink" title="日期+1"></a>日期+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'days'</span>)</span><br></pre></td></tr></table></figure><h3 id="星期-1"><a href="#星期-1" class="headerlink" title="星期+1"></a>星期+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'weeks'</span>)</span><br></pre></td></tr></table></figure><h3 id="小时-1"><a href="#小时-1" class="headerlink" title="小时+1"></a>小时+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'hours'</span>)</span><br></pre></td></tr></table></figure><h3 id="分钟-1"><a href="#分钟-1" class="headerlink" title="分钟+1"></a>分钟+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'minutes'</span>)</span><br></pre></td></tr></table></figure><h3 id="秒数-1"><a href="#秒数-1" class="headerlink" title="秒数+1"></a>秒数+1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().add(<span class="number">1</span>, <span class="string">'seconds'</span>)</span><br></pre></td></tr></table></figure><h3 id="年份-1-1"><a href="#年份-1-1" class="headerlink" title="年份-1"></a>年份-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'years'</span>)</span><br><span class="line">moment().subtract(&#123;<span class="attr">years</span>: <span class="number">1</span>&#125;)</span><br></pre></td></tr></table></figure><h3 id="月份-1-1"><a href="#月份-1-1" class="headerlink" title="月份-1"></a>月份-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'months'</span>)</span><br></pre></td></tr></table></figure><h3 id="日期-1-1"><a href="#日期-1-1" class="headerlink" title="日期-1"></a>日期-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'days'</span>)</span><br></pre></td></tr></table></figure><h3 id="星期-1-1"><a href="#星期-1-1" class="headerlink" title="星期-1"></a>星期-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'weeks'</span>)</span><br></pre></td></tr></table></figure><h3 id="小时-1-1"><a href="#小时-1-1" class="headerlink" title="小时-1"></a>小时-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'hours'</span>)</span><br></pre></td></tr></table></figure><h3 id="分钟-1-1"><a href="#分钟-1-1" class="headerlink" title="分钟-1"></a>分钟-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'minutes'</span>)</span><br></pre></td></tr></table></figure><h3 id="秒数-1-1"><a href="#秒数-1-1" class="headerlink" title="秒数-1"></a>秒数-1</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'seconds'</span>)</span><br></pre></td></tr></table></figure><h2 id="格式化时间"><a href="#格式化时间" class="headerlink" title="格式化时间"></a>格式化时间</h2><p><img src="https://gitee.com/yang_yu_xiang/BlogImages/raw/master/img/%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%B6%E9%97%B4.png" alt=""></p><h3 id="格式化年月日：-‘xxxx年xx月xx日’"><a href="#格式化年月日：-‘xxxx年xx月xx日’" class="headerlink" title="格式化年月日： ‘xxxx年xx月xx日’"></a>格式化年月日： ‘xxxx年xx月xx日’</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'YYYY年MM月DD日'</span>)</span><br></pre></td></tr></table></figure><h3 id="格式化年月日：-‘xxxx-xx-xx’"><a href="#格式化年月日：-‘xxxx-xx-xx’" class="headerlink" title="格式化年月日： ‘xxxx-xx-xx’"></a>格式化年月日： ‘xxxx-xx-xx’</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'YYYY-MM-DD'</span>)</span><br></pre></td></tr></table></figure><h3 id="格式化时分秒-24小时制-：-‘xx时xx分xx秒’"><a href="#格式化时分秒-24小时制-：-‘xx时xx分xx秒’" class="headerlink" title="格式化时分秒(24小时制)： ‘xx时xx分xx秒’"></a>格式化时分秒(24小时制)： ‘xx时xx分xx秒’</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'HH时mm分ss秒'</span>)</span><br></pre></td></tr></table></figure><h3 id="格式化时分秒-12小时制-：’xx-xx-xx-am-pm’"><a href="#格式化时分秒-12小时制-：’xx-xx-xx-am-pm’" class="headerlink" title="格式化时分秒(12小时制)：’xx:xx:xx am/pm’"></a>格式化时分秒(12小时制)：’xx:xx:xx am/pm’</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'hh:mm:ss a'</span>)</span><br></pre></td></tr></table></figure><h3 id="格式化时间戳-以毫秒为单位"><a href="#格式化时间戳-以毫秒为单位" class="headerlink" title="格式化时间戳(以毫秒为单位)"></a>格式化时间戳(以毫秒为单位)</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'x'</span>) <span class="comment">// 返回值为字符串类型</span></span><br></pre></td></tr></table></figure><h2 id="比较时间"><a href="#比较时间" class="headerlink" title="比较时间"></a>比较时间</h2><h3 id="获取两个日期之间的时间差"><a href="#获取两个日期之间的时间差" class="headerlink" title="获取两个日期之间的时间差"></a>获取两个日期之间的时间差</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> start_date = moment().subtract(<span class="number">1</span>, <span class="string">'weeks'</span>)</span><br><span class="line"><span class="keyword">let</span> end_date = moment()</span><br><span class="line"></span><br><span class="line">end_date.diff(start_date) <span class="comment">// 返回毫秒数</span></span><br><span class="line"></span><br><span class="line">end_date.diff(start_date, <span class="string">'months'</span>) <span class="comment">// 0</span></span><br><span class="line">end_date.diff(start_date, <span class="string">'weeks'</span>) <span class="comment">// 1</span></span><br><span class="line">end_date.diff(start_date, <span class="string">'days'</span>) <span class="comment">// 7</span></span><br><span class="line">start_date.diff(end_date, <span class="string">'days'</span>) <span class="comment">// -7</span></span><br></pre></td></tr></table></figure><h2 id="转化为JavaScript原生Date对象"><a href="#转化为JavaScript原生Date对象" class="headerlink" title="转化为JavaScript原生Date对象"></a>转化为JavaScript原生Date对象</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moment().toDate()</span><br><span class="line"><span class="keyword">new</span> <span class="built_in">Date</span>(moment())</span><br></pre></td></tr></table></figure><h2 id="日期格式化输出实例"><a href="#日期格式化输出实例" class="headerlink" title="日期格式化输出实例"></a>日期格式化输出实例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'MMMM Do YYYY, h:mm:ss a'</span>); <span class="comment">// 五月 24日 2019, 7:47:43 晚上</span></span><br><span class="line">moment().format(<span class="string">'dddd'</span>);                    <span class="comment">// 星期五</span></span><br><span class="line">moment().format(<span class="string">"MMM Do YY"</span>);               <span class="comment">// 5月 24日 19</span></span><br><span class="line">moment().format(<span class="string">'YYYY [escaped] YYYY'</span>);     <span class="comment">// 2019 escaped 2019</span></span><br><span class="line">moment().format();                          <span class="comment">// 2019-05-24T19:47:43+08:00</span></span><br></pre></td></tr></table></figure><h2 id="相对时间输出实例"><a href="#相对时间输出实例" class="headerlink" title="相对时间输出实例"></a>相对时间输出实例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">moment(<span class="string">"20111031"</span>, <span class="string">"YYYYMMDD"</span>).fromNow(); <span class="comment">// 8 年前</span></span><br><span class="line">moment(<span class="string">"20120620"</span>, <span class="string">"YYYYMMDD"</span>).fromNow(); <span class="comment">// 7 年前</span></span><br><span class="line">moment().startOf(<span class="string">'day'</span>).fromNow();        <span class="comment">// 20 小时前</span></span><br><span class="line">moment().endOf(<span class="string">'day'</span>).fromNow();          <span class="comment">// 4 小时内</span></span><br><span class="line">moment().startOf(<span class="string">'hour'</span>).fromNow();       <span class="comment">// 1 小时前</span></span><br></pre></td></tr></table></figure><h2 id="日历时间输出实例"><a href="#日历时间输出实例" class="headerlink" title="日历时间输出实例"></a>日历时间输出实例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">moment().subtract(<span class="number">10</span>, <span class="string">'days'</span>).calendar(); <span class="comment">// 2019年5月14日</span></span><br><span class="line">moment().subtract(<span class="number">6</span>, <span class="string">'days'</span>).calendar();  <span class="comment">// 上周六晚上7点49</span></span><br><span class="line">moment().subtract(<span class="number">3</span>, <span class="string">'days'</span>).calendar();  <span class="comment">// 本周二晚上7点49</span></span><br><span class="line">moment().subtract(<span class="number">1</span>, <span class="string">'days'</span>).calendar();  <span class="comment">// 昨天晚上7点49分</span></span><br><span class="line">moment().calendar();                      <span class="comment">// 今天晚上7点49分</span></span><br><span class="line">moment().add(<span class="number">1</span>, <span class="string">'days'</span>).calendar();       <span class="comment">// 明天晚上7点49分</span></span><br><span class="line">moment().add(<span class="number">3</span>, <span class="string">'days'</span>).calendar();       <span class="comment">// 下周一晚上7点49</span></span><br><span class="line">moment().add(<span class="number">10</span>, <span class="string">'days'</span>).calendar();      <span class="comment">// 2019年6月3日</span></span><br></pre></td></tr></table></figure><h2 id="多语言支持输出实例"><a href="#多语言支持输出实例" class="headerlink" title="多语言支持输出实例"></a>多语言支持输出实例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">moment().format(<span class="string">'L'</span>);    <span class="comment">// 2019-05-24</span></span><br><span class="line">moment().format(<span class="string">'l'</span>);    <span class="comment">// 2019-05-24</span></span><br><span class="line">moment().format(<span class="string">'LL'</span>);   <span class="comment">// 2019年5月24日</span></span><br><span class="line">moment().format(<span class="string">'ll'</span>);   <span class="comment">// 2019年5月24日</span></span><br><span class="line">moment().format(<span class="string">'LLL'</span>);  <span class="comment">// 2019年5月24日晚上7点50分</span></span><br><span class="line">moment().format(<span class="string">'lll'</span>);  <span class="comment">// 2019年5月24日晚上7点50分</span></span><br><span class="line">moment().format(<span class="string">'LLLL'</span>); <span class="comment">// 2019年5月24日星期五晚上7点50分</span></span><br><span class="line">moment().format(<span class="string">'llll'</span>); <span class="comment">// 2019年5月24日星期五晚上7点50分</span></span><br></pre></td></tr></table></figure><h2 id="将毫秒数转为时分秒-可用于时间戳转换"><a href="#将毫秒数转为时分秒-可用于时间戳转换" class="headerlink" title="将毫秒数转为时分秒(可用于时间戳转换)"></a>将毫秒数转为时分秒(可用于时间戳转换)</h2><p><strong>注意：毫秒转为其他单位时，达到你想要转的单位时，为1，超过时不管，不足时为0；</strong></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> msTime = <span class="number">4800000</span>;        <span class="comment">//80分钟</span></span><br><span class="line"> </span><br><span class="line">moment.duration(msTime).hours();       <span class="comment">//转为小时，值为1</span></span><br><span class="line">moment.duration(msTime).minutes();     <span class="comment">//转为分钟，值为20</span></span><br><span class="line">moment.duration(msTime).seconds();     <span class="comment">//转为秒，值为0</span></span><br></pre></td></tr></table></figure><p>转为其他单位：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">moment.duration(msTime, <span class="string">'seconds'</span>);        <span class="comment">//转为秒</span></span><br><span class="line">moment.duration(msTime, <span class="string">'minutes'</span>);        <span class="comment">//转为分</span></span><br><span class="line">moment.duration(msTime, <span class="string">'hours'</span>);          <span class="comment">//转为小时</span></span><br><span class="line">moment.duration(msTime, <span class="string">'days'</span>);           <span class="comment">//转为天</span></span><br><span class="line">moment.duration(msTime, <span class="string">'weeks'</span>);          <span class="comment">//转为周</span></span><br><span class="line">moment.duration(msTime, <span class="string">'months'</span>);         <span class="comment">//转为月</span></span><br><span class="line">moment.duration(msTime, <span class="string">'years'</span>);          <span class="comment">//转为年</span></span><br></pre></td></tr></table></figure><h2 id="判断一个日期是否在两个日期之间"><a href="#判断一个日期是否在两个日期之间" class="headerlink" title="判断一个日期是否在两个日期之间"></a>判断一个日期是否在两个日期之间</h2><h3 id="不包含这两个起始日期"><a href="#不包含这两个起始日期" class="headerlink" title="不包含这两个起始日期"></a>不包含这两个起始日期</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2010-10-20'</span>).isBetween(<span class="string">'2010-10-19'</span>,<span class="string">'2010-10-25'</span>); <span class="comment">// true</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2010-10-19'</span>).isBetween(<span class="string">'2010-10-19'</span>,<span class="string">'2010-10-25'</span>); <span class="comment">// false</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2010-10-25'</span>).isBetween(<span class="string">'2010-10-19'</span>,<span class="string">'2010-10-25'</span>); <span class="comment">// false</span></span><br></pre></td></tr></table></figure><h3 id="自定义是否包含起始日期"><a href="#自定义是否包含起始日期" class="headerlink" title="自定义是否包含起始日期"></a>自定义是否包含起始日期</h3><p>这里我们需要多用到两个参数：</p><ul><li>第三个参数，固定为null；</li><li>第四个参数，字符串，() 表示不包含，[] 表示包含。右括号开始日期，右括号控制结束日期<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2016-10-30'</span>).isBetween(<span class="string">'2016-10-30'</span>,<span class="string">'2016-12-30'</span>, <span class="literal">null</span>, <span class="string">'()'</span>); <span class="comment">//false</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2016-10-30'</span>).isBetween(<span class="string">'2016-10-30'</span>,<span class="string">'2016-12-30'</span>, <span class="literal">null</span>, <span class="string">'[)'</span>); <span class="comment">//true</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2016-10-30'</span>).isBetween(<span class="string">'2016-01-01'</span>,<span class="string">'2016-10-30'</span>, <span class="literal">null</span>, <span class="string">'()'</span>); <span class="comment">//false</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2016-10-30'</span>).isBetween(<span class="string">'2016-01-01'</span>,<span class="string">'2016-10-30'</span>, <span class="literal">null</span>, <span class="string">'(]'</span>); <span class="comment">//true</span></span><br><span class="line"><span class="keyword">this</span>.moment(<span class="string">'2016-10-30'</span>).isBetween(<span class="string">'2016-10-30'</span>,<span class="string">'2016-10-30'</span>, <span class="literal">null</span>, <span class="string">'[]'</span>); <span class="comment">//true</span></span><br></pre></td></tr></table></figure></li></ul></div><div><div class="my_post_copyright"><script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script><script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script><p><span>本文标题:</span><a href="/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/">moment.js使用方法总结</a></p><p><span>文章作者:</span><a href="/" title="访问 杨雨翔 的个人博客">杨雨翔</a></p><p><span>发布时间:</span>2020年11月03日 - 22:59</p><p><span>最后更新:</span>2020年11月04日 - 09:48</p><p><span>原始链接:</span><a href="/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/" title="moment.js使用方法总结">https://gitee.com/yang_yu_xiang/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/</a> <span class="copy-path" title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://gitee.com/yang_yu_xiang/MyBlog/2020/11/03/moment-js%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%80%BB%E7%BB%93/" aria-label="复制成功！"></i></span></p><p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p></div><script>var clipboard=new Clipboard(".fa-clipboard");$(".fa-clipboard").click((function(){clipboard.on("success",(function(){swal({title:"",text:"复制成功",icon:"success",showConfirmButton:!0})}))}))</script></div><div style="text-align:center;color:#ccc;font-size:16px">---------------- The End ----------------</div><footer class="post-footer"><div class="post-tags"><a href="/MyBlog/tags/Vue/" rel="tag"><i class="fa fa-tag"></i> Vue</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/MyBlog/2020/10/30/Vue3-0%EF%BC%88%E4%BA%94%EF%BC%89toRef%E5%92%8CtoRefs/" rel="next" title="Vue3.0（五）toRef和toRefs"><i class="fa fa-chevron-left"></i> Vue3.0（五）toRef和toRefs</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/MyBlog/2020/11/11/Koa%E6%A1%86%E6%9E%B6%EF%BC%88%E4%BA%94%EF%BC%89Koa%E8%BF%9E%E6%8E%A5mysql/" rel="prev" title="Koa框架（五）Koa连接mysql">Koa框架（五）Koa连接mysql <i class="fa fa-chevron-right"></i></a></div></div></footer></div></article><div class="post-spread"><div class="jiathis_style"><span class="jiathis_txt">分享到：</span> <a class="jiathis_button_fav">收藏夹</a> <a class="jiathis_button_copy">复制网址</a> <a class="jiathis_button_email">邮件</a> <a class="jiathis_button_weixin">微信</a> <a class="jiathis_button_qzone">QQ空间</a> <a class="jiathis_button_tqq">腾讯微博</a> <a class="jiathis_button_douban">豆瓣</a> <a class="jiathis_button_share">一键分享</a> <a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a> <a class="jiathis_counter_style"></a></div><script type="text/javascript">var jiathis_config={data_track_clickback:!0,summary:"",shortUrl:!1,hideMore:!1}</script><script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script></div></div></div><div class="comments" id="comments"></div></div><div class="sidebar-toggle"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div><aside id="sidebar" class="sidebar"><div id="sidebar-dimmer"></div><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">文章目录</li><li class="sidebar-nav-overview" data-target="site-overview-wrap">站点概览</li></ul><section class="site-overview-wrap sidebar-panel"><div class="site-overview"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" src="https://gitee.com/yang_yu_xiang/BlogImages/raw/master/img/psb.jpg" alt="杨雨翔"><p class="site-author-name" itemprop="name">杨雨翔</p><p class="site-description motion-element" itemprop="description"></p></div><nav class="site-state motion-element"><div class="site-state-item site-state-posts"><a href="/MyBlog/archives/"><span class="site-state-item-count">53</span> <span class="site-state-item-name">日志</span></a></div><div class="site-state-item site-state-categories"><a href="/MyBlog/categories/index.html"><span class="site-state-item-count">12</span> <span class="site-state-item-name">分类</span></a></div><div class="site-state-item site-state-tags"><a href="/MyBlog/tags/index.html"><span class="site-state-item-count">32</span> <span class="site-state-item-name">标签</span></a></div></nav><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://gitee.com/yang_yu_xiang" target="_blank" title="码云"><i class="fa fa-fw fa-git"></i>码云</a> </span><span class="links-of-author-item"><a href="http://wpa.qq.com/msgrd?v=3&uin=1372201820&site=qq&menu=yes" target="_blank" title="QQ"><i class="fa fa-fw fa-qq"></i>QQ</a> </span><span class="links-of-author-item"><a href="https://github.com/gezhicui" target="_blank" title="Github"><i class="fa fa-fw fa-github"></i>Github</a> </span><span class="links-of-author-item"><a href="mailto:1372201820@qq.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a></span></div><div class="links-of-blogroll motion-element links-of-blogroll-block"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 友情链接</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://cloudhao.top/#/search/%E5%9F%9F%E5%90%8D" title="陈昀昊的小窝" target="_blank">陈昀昊的小窝</a></li><li class="links-of-blogroll-item"><a href="http://www.shezhiwei.top/" title="佘智伟的博客" target="_blank">佘智伟的博客</a></li><li class="links-of-blogroll-item"><a href="https://blog.csdn.net/qq_43185206" title="阿呆的小鸡仔" target="_blank">阿呆的小鸡仔</a></li></ul></div></div></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#引入moment-js"><span class="nav-number">1.</span> <span class="nav-text">引入moment.js</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装"><span class="nav-number">1.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#引入"><span class="nav-number">1.2.</span> <span class="nav-text">引入</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#设定moment区域为中国"><span class="nav-number">2.</span> <span class="nav-text">设定moment区域为中国</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#方法速查"><span class="nav-number">3.</span> <span class="nav-text">方法速查</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#基本使用"><span class="nav-number">4.</span> <span class="nav-text">基本使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#获取时间"><span class="nav-number">4.1.</span> <span class="nav-text">获取时间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#获取当前时间"><span class="nav-number">4.1.1.</span> <span class="nav-text">获取当前时间</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取今天0时0分0秒"><span class="nav-number">4.1.2.</span> <span class="nav-text">获取今天0时0分0秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取本周第一天-周日Sunday-0时0分0秒"><span class="nav-number">4.1.3.</span> <span class="nav-text">获取本周第一天(周日Sunday)0时0分0秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取本周周一0时0分0秒"><span class="nav-number">4.1.4.</span> <span class="nav-text">获取本周周一0时0分0秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取当前月第一天0时0分0秒"><span class="nav-number">4.1.5.</span> <span class="nav-text">获取当前月第一天0时0分0秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取今天23时59分59秒"><span class="nav-number">4.1.6.</span> <span class="nav-text">获取今天23时59分59秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取本周最后一天-周六-23时59分59秒"><span class="nav-number">4.1.7.</span> <span class="nav-text">获取本周最后一天(周六)23时59分59秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取本周周日23时59分59秒"><span class="nav-number">4.1.8.</span> <span class="nav-text">获取本周周日23时59分59秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取当前月最后一天23时59分59秒"><span class="nav-number">4.1.9.</span> <span class="nav-text">获取当前月最后一天23时59分59秒</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取当前月的总天数"><span class="nav-number">4.1.10.</span> <span class="nav-text">获取当前月的总天数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取时间戳-以秒为单位"><span class="nav-number">4.1.11.</span> <span class="nav-text">获取时间戳(以秒为单位)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取时间戳-以毫秒为单位"><span class="nav-number">4.1.12.</span> <span class="nav-text">获取时间戳(以毫秒为单位)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取年份"><span class="nav-number">4.1.13.</span> <span class="nav-text">获取年份</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取月份"><span class="nav-number">4.1.14.</span> <span class="nav-text">获取月份</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取一个月中的某一天"><span class="nav-number">4.1.15.</span> <span class="nav-text">获取一个月中的某一天</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取一个星期中的某一天"><span class="nav-number">4.1.16.</span> <span class="nav-text">获取一个星期中的某一天</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取小时"><span class="nav-number">4.1.17.</span> <span class="nav-text">获取小时</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取分钟"><span class="nav-number">4.1.18.</span> <span class="nav-text">获取分钟</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取秒数"><span class="nav-number">4.1.19.</span> <span class="nav-text">获取秒数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取当前的年月日时分秒"><span class="nav-number">4.1.20.</span> <span class="nav-text">获取当前的年月日时分秒</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置时间"><span class="nav-number">4.2.</span> <span class="nav-text">设置时间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#设置年份"><span class="nav-number">4.2.1.</span> <span class="nav-text">设置年份</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置月份"><span class="nav-number">4.2.2.</span> <span class="nav-text">设置月份</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置某个月中的某一天"><span class="nav-number">4.2.3.</span> <span class="nav-text">设置某个月中的某一天</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置某个星期中的某一天"><span class="nav-number">4.2.4.</span> <span class="nav-text">设置某个星期中的某一天</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置小时"><span class="nav-number">4.2.5.</span> <span class="nav-text">设置小时</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置分钟"><span class="nav-number">4.2.6.</span> <span class="nav-text">设置分钟</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置秒数"><span class="nav-number">4.2.7.</span> <span class="nav-text">设置秒数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#年份-1"><span class="nav-number">4.2.8.</span> <span class="nav-text">年份+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#月份-1"><span class="nav-number">4.2.9.</span> <span class="nav-text">月份+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#日期-1"><span class="nav-number">4.2.10.</span> <span class="nav-text">日期+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#星期-1"><span class="nav-number">4.2.11.</span> <span class="nav-text">星期+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#小时-1"><span class="nav-number">4.2.12.</span> <span class="nav-text">小时+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分钟-1"><span class="nav-number">4.2.13.</span> <span class="nav-text">分钟+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#秒数-1"><span class="nav-number">4.2.14.</span> <span class="nav-text">秒数+1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#年份-1-1"><span class="nav-number">4.2.15.</span> <span class="nav-text">年份-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#月份-1-1"><span class="nav-number">4.2.16.</span> <span class="nav-text">月份-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#日期-1-1"><span class="nav-number">4.2.17.</span> <span class="nav-text">日期-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#星期-1-1"><span class="nav-number">4.2.18.</span> <span class="nav-text">星期-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#小时-1-1"><span class="nav-number">4.2.19.</span> <span class="nav-text">小时-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分钟-1-1"><span class="nav-number">4.2.20.</span> <span class="nav-text">分钟-1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#秒数-1-1"><span class="nav-number">4.2.21.</span> <span class="nav-text">秒数-1</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#格式化时间"><span class="nav-number">4.3.</span> <span class="nav-text">格式化时间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#格式化年月日：-‘xxxx年xx月xx日’"><span class="nav-number">4.3.1.</span> <span class="nav-text">格式化年月日： ‘xxxx年xx月xx日’</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#格式化年月日：-‘xxxx-xx-xx’"><span class="nav-number">4.3.2.</span> <span class="nav-text">格式化年月日： ‘xxxx-xx-xx’</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#格式化时分秒-24小时制-：-‘xx时xx分xx秒’"><span class="nav-number">4.3.3.</span> <span class="nav-text">格式化时分秒(24小时制)： ‘xx时xx分xx秒’</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#格式化时分秒-12小时制-：’xx-xx-xx-am-pm’"><span class="nav-number">4.3.4.</span> <span class="nav-text">格式化时分秒(12小时制)：’xx:xx:xx am&#x2F;pm’</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#格式化时间戳-以毫秒为单位"><span class="nav-number">4.3.5.</span> <span class="nav-text">格式化时间戳(以毫秒为单位)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#比较时间"><span class="nav-number">4.4.</span> <span class="nav-text">比较时间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#获取两个日期之间的时间差"><span class="nav-number">4.4.1.</span> <span class="nav-text">获取两个日期之间的时间差</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#转化为JavaScript原生Date对象"><span class="nav-number">4.5.</span> <span class="nav-text">转化为JavaScript原生Date对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#日期格式化输出实例"><span class="nav-number">4.6.</span> <span class="nav-text">日期格式化输出实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#相对时间输出实例"><span class="nav-number">4.7.</span> <span class="nav-text">相对时间输出实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#日历时间输出实例"><span class="nav-number">4.8.</span> <span class="nav-text">日历时间输出实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多语言支持输出实例"><span class="nav-number">4.9.</span> <span class="nav-text">多语言支持输出实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#将毫秒数转为时分秒-可用于时间戳转换"><span class="nav-number">4.10.</span> <span class="nav-text">将毫秒数转为时分秒(可用于时间戳转换)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判断一个日期是否在两个日期之间"><span class="nav-number">4.11.</span> <span class="nav-text">判断一个日期是否在两个日期之间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#不包含这两个起始日期"><span class="nav-number">4.11.1.</span> <span class="nav-text">不包含这两个起始日期</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义是否包含起始日期"><span class="nav-number">4.11.2.</span> <span class="nav-text">自定义是否包含起始日期</span></a></li></ol></li></ol></li></ol></div></div></section></div></aside></div></main><footer id="footer" class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2021</span> <span class="with-love"><i class="fa fa-send"></i> </span><span class="author" itemprop="copyrightHolder">杨雨翔</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span class="post-meta-item-text">站点总字数&#58;</span> <span title="站点总字数">61.9k</span></div><div class="busuanzi-count"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="site-uv">本站访问数 <i class="fa fa-user"></i> <span class="busuanzi-value" id="busuanzi_value_site_uv"></span> 人次 </span><span class="site-pv">本站总访问量 <i class="fa fa-eye"></i> <span class="busuanzi-value" id="busuanzi_value_site_pv"></span> 次</span></div></div></footer><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span id="scrollpercent"><span>0</span>%</span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/MyBlog/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/MyBlog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/MyBlog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/MyBlog/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/MyBlog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/MyBlog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script><script type="text/javascript" src="/MyBlog/js/src/utils.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/motion.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/affix.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/schemes/pisces.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/scrollspy.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/post-details.js?v=5.1.4"></script><script type="text/javascript" src="/MyBlog/js/src/bootstrap.js?v=5.1.4"></script><script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="//unpkg.com/valine/dist/Valine.min.js"></script><script type="text/javascript">var GUEST=["nick","mail","link"],guest="nick";guest=guest.split(",").filter(e=>GUEST.indexOf(e)>-1),new Valine({el:"#comments",verify:!1,notify:!1,appId:"i5Tl5zN4f4LxoJgipanUuaml-gzGzoHsz",appKey:"wqw6uYNCQkeVxBffKebM29NH",placeholder:"说点什么吧...",avatar:"mm",guest_info:guest,pageSize:"10"})</script><script type="text/javascript">var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":/json$/i.test(search_path)&&(isXml=!1);var path="/MyBlog/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")};function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map((function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}})).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach((function(n){var r=!1,s=0,a=0,i=n.title.trim(),c=i.toLowerCase(),l=n.content.trim().replace(/<[^>]+>/g,""),h=l.toLowerCase(),p=decodeURIComponent(n.url),u=[],f=[];if(""!=i&&(e.forEach((function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}u=u.concat(e(t,c,!1)),f=f.concat(e(t,h,!1))})),(u.length>0||f.length>0)&&(r=!0,s=u.length+f.length)),r){function d(e,o,n,r){for(var s=r[r.length-1],i=s.position,c=s.word,l=[],h=0;i+c.length<=n&&0!=r.length;){c===t&&h++,l.push({position:i,length:c.length});var p=i+c.length;for(r.pop();0!=r.length&&(i=(s=r[r.length-1]).position,c=s.word,p>i);)r.pop()}return a+=h,{hits:l,start:o,end:n,searchTextCount:h}}[u,f].forEach((function(t){t.sort((function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length}))}));var g=[];0!=u.length&&g.push(d(0,0,i.length,u));for(var v=[];0!=f.length;){var $=f[f.length-1],C=$.position,m=$.word,x=C-20,w=C+80;x<0&&(x=0),w<C+m.length&&(w=C+m.length),w>l.length&&(w=l.length),v.push(d(0,x,w,f))}v.sort((function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start}));var y=parseInt("1");function T(t,e){var o="",n=e.start;return e.hits.forEach((function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r})),o+=t.substring(n,e.end)}y>=0&&(v=v.slice(0,y));var b="";0!=g.length?b+="<li><a href='"+p+"' class='search-result-title'>"+T(i,g[0])+"</a>":b+="<li><a href='"+p+"' class='search-result-title'>"+i+"</a>",v.forEach((function(t){b+="<a href='"+p+'\'><p class="search-result">'+T(l,t)+"...</p></a>"})),b+="</li>",o.push({item:b,searchTextCount:a,hitCount:s,id:o.length})}})),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort((function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id}));var a='<ul class="search-result-list">';o.forEach((function(t){a+=t.item})),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click((function(t){t.stopPropagation(),!1===isfetched?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()})),$(".popup-btn-close").click(onPopupClose),$(".popup").click((function(t){t.stopPropagation()})),$(document).on("keyup",(function(t){27===t.which&&$(".search-popup").is(":visible")&&onPopupClose()}))</script><script src="/MyBlog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/MyBlog/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"log":false});</script></body></html>